<template>
  <div class="home-star">
    <div class="home-star-title">当日之星
      <el-date-picker
        style="width: 200px;flex-grow: 0;"
        v-model="val"
        type="date"
        format="YYYY-MM-DD"
        valueFormat="YYYY-MM-DD"
        @change="onChange"
      />
    </div>
    <div class="home-star-list">
      <div
        v-for="(item, index) in list"
        :key="index"
        class="home-star-item"
      >
        <div>
          <img class="home-star-image" src="../images/star.png" alt="">
          <div class="home-star-item-title">{{ item.title }}</div>
        </div>

        <div>
          <div class="home-star-name">{{ item.name }}</div>
          <div class="home-star-text">{{ map.get(item.title) || '--' }}：{{ item.value }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { getTodayStar } from '../api'
import dayjs from 'dayjs'

const val = ref(dayjs().format('YYYY-MM-DD'))
const list = ref([])

const map = new Map([
  ['销售冠军', '销售额'],
  ['接待冠军', '接待量'],
  ['转化冠军', '转化率'],
  ['响应冠军', '响应时间'],
  ['答问比冠军', '问答比'],
])

getTodayStar({ date: val.value })
  .then(res => {
    list.value = res || []
  })

const onChange = () => {
  getTodayStar({ date: val.value })
  .then(res => {
    list.value = res || []
  })
}
</script>

<style scoped lang="scss">
.home-star {
  min-height: 318px;
  background: #FFFFFF;
  border-radius: 12px;
  padding: 25px;
  box-sizing: border-box;
  &-title {
    font-family: PingFangSC-Medium;
    font-weight: 500;
    font-size: 15px;
    color: #333333;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between
  }
  &-list {
    display: flex;
    flex-wrap: wrap;
    margin-left: -20px;
  }
  &-item {
    width: 147px;
    height: 233px;
    padding: 19px;
    box-sizing: border-box;
    background: #FFF6F1;
    border: 1px solid #DDA081;
    border-radius: 8px;
    margin-top: 20px;
    margin-left: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }

  &-image {
    width: 45px;
  }

  &-item-title {
    font-family: DOUYINSANSBOLD-GB;
    font-weight: GB;
    font-size: 14px;
    color: #333333;
    margin-top: 5px;
  }

  &-name {
    font-family: PingFangHK-SNaNpxibold;
    font-weight: 600;
    font-size: 14px;
    color: #094DB2;
  }

  &-text {
    font-family: PingFangHK-Regular;
    font-weight: 400;
    font-size: 12px;
    color: #333333;
    margin-top: 5px;
  }
}
</style>
